#include "mypushbutton.h"

MyPushButton::MyPushButton(const QString &normalIconPath, const QString &pressedIconPath,
                           const QString& atIconPath, QWidget *parent)
    : QPushButton(parent)
    , m_normalIcon(normalIconPath)
    , m_pressedIcon(pressedIconPath)
    , m_atIcon(atIconPath)
{
    setIcon(m_normalIcon);
}

void MyPushButton::enterEvent(QEnterEvent *event)
{
    at = true;
    setIcon(m_atIcon);
}


void MyPushButton::leaveEvent(QEvent *event)
{
    at = false;
    setIcon(m_normalIcon);
}

void MyPushButton::mousePressEvent(QMouseEvent *event)
{
    if (at)
    {
        setIcon(m_pressedIcon);
        QPushButton::mousePressEvent(event);
    }
}

void MyPushButton::mouseReleaseEvent(QMouseEvent *event)
{
    if (at)
        setIcon(m_atIcon);
    else
        setIcon(m_normalIcon);
    QPushButton::mouseReleaseEvent(event);
}
